Attributed String Creator

Attributed String Creator Help

How to get your text in, format it, and get the code you need. New to the app? See what it does.

Step 1

Getting text in

The top half of the window is a text editor. Whatever's in it is turned into code underneath, and the code changes as you type.

  • Type straight into the editor.
  • Paste Text in the toolbar replaces everything in the editor with what's on the clipboard, formatting included. Copy from Pages, TextEdit, Word or a web page.
  • Open (⌘O) reads RTF, Word (.docx), HTML and plain text files. You can also open these files in Attributed String Creator from Finder.
  • Save (⌘S) keeps your formatted text as an RTF file, so you can come back to it.

Clear Text empties the editor. Clear Formatting keeps the words and resets them to plain Helvetica.

Step 2

Formatting

The editor works like TextEdit. Select some text, then:

  • use the format bar above the editor for the font, style, size, colour, alignment, lists and line spacing;
  • click Fonts or Colors in the toolbar for the Mac's Fonts and Colours panels, which also do underline and strikethrough colours, and text background colours;
  • or use the Format menu for bold, italic, kerning, ligatures, baseline and alignment.

Paragraph settings like indents and line spacing apply to the whole paragraph the cursor is in.

Step 3

Choosing the code

The bar between the editor and the code sets what kind of code you get.

  • Variable or Method: a variable declaration, or a function that builds the string and returns it.
  • The name field names the variable or function, and everything declared with it. Spaces are removed as you type. Leave it empty to use myString.
  • Objective-C or Swift.
  • iOS Code or macOS Code: UIFont and UIColor for iOS, or NSFont and NSColor for macOS.
Attributed String Creator with a styled sale banner in the editor, Variable, Swift and iOS Code selected, and the Swift code underneath
A centred heading and a highlighted offer, as Swift for iOS

Fine-tuning

The Options menu

The Options menu in the menu bar changes how the code is written.

  • Verbose Paragraph PropertiesDeclare every paragraph property, instead of only the ones that differ from the defaults.
  • Include Tab Stops For ParagraphsAdd each paragraph's tab stops to the code. Text from documents often has tab stops it never uses, so turn this off for shorter code.
  • Declare variables with rangeOfStringFind each range by searching the text for the words it covers, instead of using fixed positions.
  • Dark Input BackgroundShow the editor with a dark background, handy for checking light-coloured text.
  • Show Welcome Text at LaunchStart with the welcome text, or an empty editor.

Step 4

Using the code

Copy Code in the toolbar puts all of the code on the clipboard. Paste it into your project, then give the string to anything that shows attributed text:

// As a variable
titleLabel.attributedText = myString

// As a method
titleLabel.attributedText = saleBanner()

On macOS, use attributedStringValue for an NSTextField, or the text storage of an NSTextView.

If the code uses a font that isn't part of iOS, a warning appears under it. Read on to add the font to your app.

Custom fonts

Adding a custom font to an iOS app

iOS comes with plenty of fonts, but not every font on your Mac. When your text uses one iOS doesn't have, Attributed String Creator warns you and names the font exactly as the code refers to it.

The warning: CAUTION: The following font you are using isn't part of the iOS SDK: SignPainter-HouseScript. Find out how to import this in the help section.
The warning under the code

Add the font before you use the code. If the font isn't in your app, UIFont(name:size:) finds nothing, and the ! in the Swift code stops the app. If you'd rather not add it, change the text to a font iOS has.

  1. Find the font file. Open Font Book, search for the font, then Control-click it and choose Show in Finder. Check the font's licence lets you include it in an app.
  2. Add it to your project. Drag the file into Xcode's Project navigator. In the dialog, choose to copy the file if needed and tick your app's target.
  3. List it in Info.plist. In your target's Info tab, add a row called Fonts provided by application (UIAppFonts). Give it an item with the font's file name, including the extension, for example BrandFont-Bold.otf.
  4. Use the code as normal. Build and run. The name in the generated code is the font's PostScript name, which is what UIFont(name:size:) needs, so it works as it is.

Still stuck? Email support@bridgetech.io.

← Back to Attributed String Creator